package cn.boy.service;

import java.io.InputStream;
import java.util.Properties;

import cn.boy.dao.StudentDao;
import cn.boy.dao.StudentDaoFactory;

public class DormitoryServiceFactory {
	
	private DormitoryService service;
	private static DormitoryServiceFactory instance = new DormitoryServiceFactory();

	private DormitoryServiceFactory() {

		try {
			Properties prop = new Properties();
			InputStream is = StudentDaoFactory.class.getClassLoader()
					.getResourceAsStream("config.properties");
			prop.load(is);
			String dormitoryServiceClass = prop.getProperty("dormitoryServiceClass");
			Class clazz = Class.forName(dormitoryServiceClass);
			service = (DormitoryService) clazz.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ExceptionInInitializerError(e);
		}

	}

	public static DormitoryServiceFactory getInstance() {
		return instance;
	}

	public DormitoryService getDormitoryService() {
		return service;
	}

}
